package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.HigherStatus;
import com.ruoyi.common.enums.TenantStatus;
import com.ruoyi.common.utils.DoubleUtil;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysHigher;
import com.ruoyi.system.domain.SysTenant;
import com.ruoyi.system.service.ISysHigherService;
import com.ruoyi.system.service.ISysTenantService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 涨租Controller
 * 
 * @author ruoyi
 * @date 2020-06-28
 */
@Controller
@RequestMapping("/system/higherLog")
public class SysHigherLogController extends BaseController {
    private String prefix = "system/higher";

    @Autowired
    private ISysTenantService sysTenantService;

    @Autowired
    private ISysHigherService sysHigherService;

    @RequiresPermissions("system:higherLog:view")
    @GetMapping()
    public String higher() {
        return prefix + "/higherLog";
    }

    /**
     * 查询涨租列表
     */
    @RequiresPermissions("system:higherLog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysHigher sysHigher) {
        startPage();
        List<SysHigher> list = sysHigherService.selectSysHigherLogList(sysHigher);
        return getDataTable(list);
    }

    /**
     * 涨租详情
     */
    @RequiresPermissions("system:higherLog:detail")
    @GetMapping("/detail/{higherId}")
    public String detail(@PathVariable("higherId") Long higherId, ModelMap mmap) {
        SysHigher sysHigher = sysHigherService.selectSysHigherById(higherId);

        Double higherBeforeRentFee = sysHigher.getHigherRentFee() / (1 + Double.parseDouble(sysHigher.getRisePriceRatio()));
        //涨租前租金
        higherBeforeRentFee = DoubleUtil.round(higherBeforeRentFee,2);
        mmap.put("higherBeforeRentFee", higherBeforeRentFee);

        Double risePriceRatio = Double.parseDouble(sysHigher.getRisePriceRatio()) * 100;
        sysHigher.setRisePriceRatio(risePriceRatio.toString());
        sysHigher.setHigherRentFee(DoubleUtil.round(sysHigher.getHigherRentFee(),2));
        mmap.put("sysHigher", sysHigher);
        return prefix + "/logDetail";
    }
}
